'''
Created on 27/04/2012

@author: Bruna, Bruno
'''

def calculate_hue(red, green, blue):
    max_value = max(red, green, blue)
    min_value = min(red, green, blue)
  
    try:
        if (max_value == red):
            if (green >= blue):
                return 60 * (green-blue)/(max_value - min_value)
            else:
                return 60 * (green-blue)/(max_value - min_value) + 360
        elif (max_value == green):
            return 60 * (blue-red)/(max_value - min_value) + 120
        else:
            return 60 * (red-green)/(max_value - min_value) + 240
    except ZeroDivisionError:
        return -1

def calculate_rgb_normalized(red, green, blue):
    sum = float(red + green + blue)
    normalized_r = red / sum
    normalized_g = green / sum
    normalized_b = blue / sum
    
    return normalized_r, normalized_g, normalized_b